<!--
  * 商品明细
  *
-->
<template>
  <a-table :dataSource="tableData" :columns="columns" :pagination="false" :scroll="{ x: 'max-content' }" rowKey="id" size="small" bordered>
    <template #bodyCell="{ text, record, index, column }">
      <template v-if="column.dataIndex === 'goods_name'">
        <CopyText :text="record?.goods?.goods_name">
          {{ record?.goods?.goods_name }}
        </CopyText>
      </template>
      <template v-if="column.dataIndex === 'img'">
        <div class="smart-table-operate">
          <a-image :width="record?.goods?.img ? 30 : 50" :src="record?.goods?.img || failImg" />
        </div>
      </template>
      <template v-if="column.dataIndex === 'type'">
        <span>
          <a-tag :color="tagType[text]">{{ getDescByValue('GOODS_TYPE_ENUM', text) }}</a-tag>
        </span>
      </template>
    </template>
  </a-table>
</template>
<script setup lang="ts">
import { reactive, watch, ref } from 'vue'
import { useEnums } from '@/hooks/plugins/useEnums'
import failImg from '@/assets/images/notice/failImg.png'
const { getDescByValue } = useEnums()
const props = defineProps({
  enterpriseId: {
    type: Array,
    default: null
  }
})
const tagType = ref({
  1: 'error',
  2: 'warning',
  3: 'processing',
  4: 'success',
  5: 'cyan',
  6: 'orange'
})
const columns = reactive([
  {
    title: '商品名称',
    dataIndex: 'goods_name'
  },
  {
    title: '图片',
    dataIndex: 'img'
  },
  {
    title: '规格条码',
    dataIndex: ['spec', 'barcode']
  },
  {
    title: '规格',
    dataIndex: ['spec', 'spec_name']
  },
  {
    title: '单位',
    dataIndex: ['spec', 'unit_name']
  },
  {
    title: '订单数量',
    dataIndex: 'num'
  },
  {
    title: '指导单价',
    dataIndex: 'sale_price'
  },
  {
    title: '下单单价',
    dataIndex: 'real_price'
  },
  {
    title: '订单金额',
    dataIndex: 'total_price'
  },
  {
    title: '类型',
    dataIndex: 'type'
  },
  {
    title: '商品备注',
    dataIndex: 'remark'
  }
])

const tableData = ref([])

watch(
  () => props.enterpriseId,
  (e) => {
    if (e) {
      tableData.value = e
    }
  },
  { immediate: true }
)
</script>
